/**
 *  Copyright (C) 2008-2013  Telosys project org. ( http://www.telosys.org/ )
 *
 *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.gnu.org/licenses/lgpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.telosys.persistence.metadata;

import java.lang.reflect.Field;
import java.sql.Types;


/**
 * Utility class to retrieve JDBC types as String
 * 
 * NB : For future use (not yet qualified)
 * 
 * @author Olivier Laurendeau 
 * 
 */
public class DbTypes {

//    public static String get(int sqlType)
//    {
//        String res ="???";
//       
//        if (Types.ARRAY == sqlType) res ="Array";
//        if (Types.BIGINT == sqlType) res ="Bigint";
//        if (Types.BINARY == sqlType) res ="Binary";
//        if (Types.BIT == sqlType) res ="Bit";
//        if (Types.BLOB == sqlType) res ="Blob";
//        if (Types.BOOLEAN == sqlType) res ="Boolean";
//        if (Types.CHAR == sqlType) res ="Char";
//        if (Types.CLOB == sqlType) res ="Clob";
//        if (Types.DATALINK == sqlType) res ="Datalink";
//        if (Types.DATE == sqlType) res ="Date";
//        if (Types.DECIMAL == sqlType) res ="Decimal";
//        if (Types.DISTINCT == sqlType) res ="Distinct";
//        if (Types.DOUBLE == sqlType) res ="Double";
//        if (Types.FLOAT == sqlType) res ="Float";
//        if (Types.INTEGER == sqlType) res ="Integer";
//        if (Types.JAVA_OBJECT == sqlType) res ="JavaObject";
//        //if (Types.LONGNVARCHAR == sqlType) res ="LongNVarchar"; // after JDK 1.4  
//        if (Types.LONGVARBINARY == sqlType) res ="LongVarBinary";
//        if (Types.LONGVARCHAR == sqlType) res ="LongVarChar";
//        //if (Types.NCHAR == sqlType) res ="NChar"; // after JDK 1.4
//        //if (Types.NCLOB == sqlType) res ="NClob"; // after JDK 1.4
//        if (Types.NULL == sqlType) res ="Null";
//        if (Types.NUMERIC == sqlType) res ="Numeric";
//        //if (Types.NVARCHAR == sqlType) res ="NVarChar"; // after JDK 1.4
//        if (Types.OTHER == sqlType) res ="Other";
//        if (Types.REAL == sqlType) res ="Real";
//        if (Types.REF == sqlType) res ="Ref";
//        // if (Types.ROWID == sqlType) res ="RowId"; // after JDK 1.4
//        if (Types.SMALLINT == sqlType) res ="SmallInt";
//        // if (Types.SQLXML == sqlType) res ="SqlXml"; // after JDK 1.4
//        if (Types.STRUCT == sqlType) res ="Struct";
//        if (Types.TIME == sqlType) res ="Time";
//        if (Types.TIMESTAMP == sqlType) res ="TimeStamp";
//        if (Types.TINYINT == sqlType) res ="TinyInt";
//        if (Types.VARBINARY == sqlType) res ="VarBinary";
//        if (Types.VARCHAR == sqlType) res ="VarChar";
//        
//        return res;
//    }

    public static String get(int iJdbcType)
    {
        Field[] arrayFields = Types.class.getDeclaredFields();
        for (int i=0; i < arrayFields.length;i++ ) 
        {
            Field f = arrayFields[i];
            try {
                if ( f.getInt(f) == iJdbcType )
                {
                    return f.getName();
                }
            } catch (IllegalArgumentException e) {
                return "(ERROR!)";
                //throw new TelosysRuntimeException("Illegal Argument Exception",e);
            } catch (IllegalAccessException e) {
                return "(ERROR!)";
                //throw new TelosysRuntimeException("Illegal Acces Exception",e);
            }   
        }
        return "???";        
    }
    
}
